let path = "http://localhost:8080/Saxon_Blog_war/";

$(function () {
    $.ajax({
        url: path + "/admin/getBlogWithType",
        type: "GET",
        success: function (data) {
            for (let i = 0; i < data.length; i++) {
                $("#tbody").append("<tr>\n" +
                    "    <td style='width: 100px'>" + (i + 1) + "</td>\n" +
                    "    <td>" + data[i].id + "</td>\n" +
                    "    <td>" + data[i].title + "</td>\n" +
                    "    <td style='height: 20px;overflow: hidden;text-overflow: ellipsis; white-space: nowrap;'>" + data[i].introduction+ "</td>\n" +
                    "    <td>" + formatDate(data[i].createTime )+ "</td>\n" +
                    "    <td>" + data[i].blogType.typeName + "</td>\n" + "</tr>")
            }
        }
    })
    $.ajax({
        url: path + "/admin/queryUserNum",
        type: "GET",
        success: function (data) {
           $("#userNum").text(data);
        }
    })
    $.ajax({
        url: path + "/admin/blogNum",
        type: "GET",
        success: function (data) {
           $("#blogNum").text(data);
        }
    })


})
//时间戳转换方法    date:时间戳数字
function formatDate(date) {
    var date = new Date(date);
    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return YY + MM + DD + " " + hh + mm + ss;
}

